* This code replicates the statistical results reported in Cermeño, Enflo, and Lindvall, "Railways and Reform"

* Change the current directory to where you keep the file "Cermeno_et_al_replication.dta" before you run the code

use Cermeno_et_al_replication.dta, clear

* Table 1 (running this code generates the means that are listed in Table 1 in the paper)

foreach var in "s_permfolkschool" "s_ambulatory" "s_elementary" "s_homeschool" "s_other" "s_noschool" {
	sum `var'
}

* Tables 2-4: Estimates (running this code generates the estimates that are reported in Tables 2-4 in the paper)

global controls "avg_gdpcap d_town postalrays sd_elevation_deanery DistStockholm pparticipation bishop1868 railplacebodummy2" /// Defines the control variables

foreach dep in "s_permfolkschool" "s_ambulatory" "GeoHistCatechism" { /// Runs regression analyses for the three outcome variables we are interested in

reg `dep' railaccess, cluster(Inspector)
est sto col1_`dep'

reg `dep' railaccess $controls, cluster(Inspector)
est sto col2_`dep'

reg `dep' railaccess within30 walkaccess30 $controls, cluster(Inspector)
est sto col3_`dep'

reg `dep' railaccess within20 walkaccess20 $controls, cluster(Inspector)
est sto col4_`dep'

reg `dep' railaccess within30 walkaccess30 destinationrail $controls, cluster(Inspector)
est sto col5_`dep'

reg `dep' railaccess within20 walkaccess20 destinationrail $controls, cluster(Inspector)
est sto col6_`dep'

}

* Tables 2-4: Tables (running this code, after generating the estimates, collects the regression results and produces tables that match Tables 2-4 in the paper)

esttab col1_s_permfolkschool col2_s_permfolkschool col3_s_permfolkschool col4_s_permfolkschool col5_s_permfolkschool col6_s_permfolkschool, title("Regression Analyses: Children in Permanent Public Schools") order(railaccess within30 walkaccess30 within20 walkaccess20 destinationrail $controls) nomtitles star(* 0.10 ** 0.05 *** 0.01) b(1) se(1)

esttab col1_s_ambulatory col2_s_ambulatory col3_s_ambulatory col4_s_ambulatory col5_s_ambulatory col6_s_ambulatory, title("Regression Analyses: Children in Ambulatory Schools") order(railaccess within30 walkaccess30 within20 walkaccess20 destinationrail $controls) nomtitles star(* 0.10 ** 0.05 *** 0.01) b(1) se(1)

esttab col1_GeoHistCatechism col2_GeoHistCatechism col3_GeoHistCatechism col4_GeoHistCatechism col5_GeoHistCatechism col6_GeoHistCatechism, title("Regression Analyses: Geography and History") order(railaccess within30 walkaccess30 within20 walkaccess20 destinationrail $controls) nomtitles star(* 0.10 ** 0.05 *** 0.01) b(1) se(1)

* Regression Estimates in Supplementary Materials (running this code generates the estimates that are reported in the regression tables in the supplementary materials)

foreach dep in "s_noschools" "s_otherpublic" "s_homeschool" "s_folkschool" "s_elementary" "RelHistCatechism" "SwedishCatechism" "NaturalCatechism" "GeometryCatechism" "AccCatechism" "WritingCatechism" "SingingCatechism" "GymCatechism" { /// Runs regression analyses for other outcome variables that are not the central concern of the article

reg `dep' railaccess, cluster(Inspector)
est sto col1_`dep'

reg `dep' railaccess $controls, cluster(Inspector)
est sto col2_`dep'

reg `dep' railaccess within30 walkaccess30 $controls, cluster(Inspector)
est sto col3_`dep'

reg `dep' railaccess within20 walkaccess20 $controls, cluster(Inspector)
est sto col4_`dep'

reg `dep' railaccess within30 walkaccess30 destinationrail $controls, cluster(Inspector)
est sto col5_`dep'

reg `dep' railaccess within20 walkaccess20 destinationrail $controls, cluster(Inspector)
est sto col6_`dep'

}

* Correlation Matrix (running this code generates the bivariate correlations that are reported in the correlation matrix in the supplementary materials)

global controls "avg_gdpcap d_town postalrays sd_elevation_deanery DistStockholm pparticipation bishop1868 railplacebodummy2" /// Defines the control variables

correlate s_permfolkschool GeoHistCatechism railaccess destinationrail within20 within30 walkaccess20 walkaccess30 $controls